<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>属性的简洁表示法</title>
	</head>
	<body>
		<script>
			
			const foo = "baz";
			const baz = {foo};
			console.log(baz); //{foo:'baz'};
			
			let obj = (x,y) => {
				return {x,y}; //相当于，{x:x,y:y}
			}
			console.log(obj(2,3)); //{x:2,y:3}
			
			//最常用的方法的简写：
			const o = {
				methods(){
					console.log('o');
				}
			}
			o.methods();
			//等同于
			const o1 = {
				methods:function(){
					console.log("o1");
				}
			}
			o1.methods();
			
			
			//属性名表达式,允许给键名当成变量处理
			
			const last = 'zzz';
			const person = {
				name:"zha",
				[last]:"hello"
			}
			console.log(person);
			console.log(person[last]);
			
			//假如对象设置了getter和setter函数，则name名存在get,set方法中，需要取得这两个方法
			const obj = {
			  get foo() {},
			  set foo(x) {}
			};
			
			obj.foo.name
			// TypeError: Cannot read property 'name' of undefined
			
			const descriptor = Object.getOwnPropertyDescriptor(obj, 'foo');
			
			descriptor.get.name // "get foo"
			descriptor.set.name // "set foo"
			
			
			
			
		</script>
	</body>
</html>
